<script src="./products.js"></script>
<script>
console.log(products)
/*
  1 求所有商品的单价之和（priceDisplay.currentPrice)
*/
let sum = 0
for (let i=0; i<products.length; i++) {
  sum += products[i].priceDisplay.currentPrice
}
products.reduce(function(sum, p) {
  return sum + p.priceDisplay.currentPrice
}, 0)

/*
  2 统计一共有多少种商品类型 (productType属性)
*/
const types = []
for(let i=0; i<products.length; i++) {
  let p = products[i]
  if (types.indexOf(p.productType) === -1) {
    types.push(p.productType)
  }
}
console.log(types)

const types2 = []
products.forEach(function(p) {
  if (types2.indexOf(p.productType) === -1) {
    types2.push(p.productType)
  }
})
console.log(types2)

console.log(products.reduce(function(types, p) {
  if (types.indexOf(p.productType) === -1) {
    types.push(p.productType)
  }
  return types
}, []))


</script>